<?php

	include '../common.php';
	
	$json = json_decode(file_get_contents('php://input'));
	
	$movieId = $json->{"movie_id"};
	
	
	$movieId = 3;
	
	$conn = linkMySql();

	$sql = "SELECT ".NEWEST_MOVIE.".".NEWEST_MOVIE_SCORE. "," 
       . MOVIE_DETAILS_TABLE.".".MOVIE_CAST.","
       . NEWEST_MOVIE.".".NEWEST_MOVIE_AREA. ","
       . NEWEST_MOVIE.".".MOVIE_IMG.","
       . NEWEST_MOVIE.".".NEWEST_MOVIE_DATE.","
       . NEWEST_MOVIE.".".NEWEST_MOVIE_TYPE.","
       . MOVIE_DETAILS_TABLE.".".MOVIE_RESUME_SYNOPSIS.","
       . USER_TABLE.".".USER_HEADER ." AS user_img,"
       . USER_TABLE.".".USER_ID." AS user_id "
	   . " FROM ".NEWEST_MOVIE .",".  MOVIE_DETAILS_TABLE.",". USER_TABLE .",". MIDDLE_NEWEST_MOVIE
	   . " WHERE ". NEWEST_MOVIE.".".MOVIE_ID." = $movieId AND "
	   . NEWEST_MOVIE.".".MOVIE_ID." = ". MOVIE_DETAILS_TABLE.".".MOVIE_RESUME_ID
	   . " AND ". MIDDLE_NEWEST_MOVIE.".".PRAISE_OR_SCAN. " = 0 AND "
			. MIDDLE_NEWEST_MOVIE.".".MIDDLE_USER_ID." = ". USER_TABLE.".".USER_ID;
	
	$result = mysqli_query($conn, $sql);
	
	$baseInfos = mysqli_fetch_assoc($result);
	
	while ($array = mysqli_fetch_assoc($result)) {
		$usersArray[] = array("user_header" => $array['user_img'], "user_id" => $array['user_id']);
	}
	
	
	$usersArray[] = array("user_header" => $baseInfos['user_img'], "user_id" => $baseInfos['user_id']);
	
	$returnResult = array("tag" => MOVIE_DETAIL_INFOS, "score" => $baseInfos['newest_movie_score'],
			 "cast" => $baseInfos['movie_resume_cast'], "area" => $baseInfos['newest_movie_area'],
			 "picture" => $baseInfos['newest_movie_sea_pic'], "date" => $baseInfos['newest_movie_date'],
			 "type" => $baseInfos['newest_movie_type'], "synopsis" => $baseInfos['movie_resume_synopsis'],
			 "users"=>$usersArray);
	
	echo json_encode($returnResult);die;
	
?>